home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / src / dfr8f.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-30  |  13.5 KB  |  454 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.3 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/dfr8f.c,v 1.3 1992/10/30 18:36:52 koziol beta koziol $
  30.  
  31. $Log: dfr8f.c,v $
  32.  * Revision 1.3  1992/10/30  18:36:52  koziol
  33.  * Fixed casts in a bunch of functions to make the SGI ANSI compiler happy
  34.  *
  35.  * Revision 1.2  1992/09/11  14:15:04  koziol
  36.  * Changed Fortran stubs' parameter passing to use a new typedef, intf,
  37.  * which should be typed to the size of an INTEGER*4 in whatever Fortran
  38.  * compiler the C functions need to be compatible with.  (This is mostly
  39.  * for the PC and possibly for the Mac)
  40.  *
  41.  * Revision 1.1  1992/08/25  21:40:44  koziol
  42.  * Initial revision
  43.  *
  44. */
  45. /*-----------------------------------------------------------------------------
  46.  * File:    dfr8F.c
  47.  * Purpose: C stubs for Fortran RIS routines
  48.  * Invokes: dfr8.c dfkit.c
  49.  * Contents: 
  50.  *  d8spal:     Set palette to write out with subsequent images
  51.  *  d8first:    Call DFR8restart to reset sequencing to first image
  52.  *  d8igdim:    Call DFR8getdims to get dimensions of next image
  53.  *  d8igimg:    Call DFR8getimage to get next image
  54.  *  d8ipimg:    Call DFR8putimage to write image to new file
  55.  *  d8iaimg:    Call DFR8putimage to add image to existing file
  56.  *  d8irref:    Call DFR8readref to set ref to get next
  57.  *  d8iwref:    Call DFR8writeref to set ref to put next
  58.  *  d8inims:    Call DFR8nimages to get the number of images in the file
  59.  *  d8lref:     Call DFR8lastref to get ref of last image read/written
  60.  *  dfr8lastref:    Call DFR8lastref to get ref of last image read/written
  61.  *  dfr8setpalette: Set palette to write out with subsequent images
  62.  *  dfr8restart:    Call DFR8restart to reset sequencing to first image
  63.  * Remarks: none
  64.  *---------------------------------------------------------------------------*/
  65.  
  66. #include "hdf.h"
  67.  
  68. #ifndef DFR8_FNAMES
  69. #   define DFR8_FNAMES
  70. #ifdef DF_CAPFNAMES
  71. #   define nd8spal   FNAME(D8SPAL)
  72. #   define nd8first  FNAME(D8FIRST)
  73. #   define nd8igdim  FNAME(D8IGDIM)
  74. #   define nd8igimg  FNAME(D8IGIMG)
  75. #   define nd8ipimg  FNAME(D8IPIMG)
  76. #   define nd8iaimg  FNAME(D8IAIMG)
  77. #   define nd8irref  FNAME(D8IRREF)
  78. #   define nd8iwref  FNAME(D8IWREF)
  79. #   define nd8inims  FNAME(D8INIMS)
  80. #   define nd8lref   FNAME(D8LREF)
  81. #   define ndfr8lastref      FNAME(DFR8LASTREF)
  82. #   define ndfr8setpalette   FNAME(DFR8SETPALETTE)
  83. #   define ndfr8restart  FNAME(DFR8RESTART)
  84. #else   /* !DF_CAPFNAMES */
  85. #   define nd8spal   FNAME(d8spal)
  86. #   define nd8first  FNAME(d8first)
  87. #   define nd8igdim  FNAME(d8igdim)
  88. #   define nd8igimg  FNAME(d8igimg)
  89. #   define nd8ipimg  FNAME(d8ipimg)
  90. #   define nd8iaimg  FNAME(d8iaimg)
  91. #   define nd8irref  FNAME(d8irref)
  92. #   define nd8iwref  FNAME(d8iwref)
  93. #   define nd8inims  FNAME(d8inims)
  94. #   define nd8lref   FNAME(d8lref)
  95. #   define ndfr8lastref      FNAME(dfr8lastref)
  96. #   define ndfr8setpalette   FNAME(dfr8setpalette)
  97. #   define ndfr8restart  FNAME(dfr8restart)
  98. #endif /* DF_CAPFNAMES */
  99. #endif /* DFR8_FNAMES */
  100.  
  101. /*-----------------------------------------------------------------------------
  102.  * Name:    d8spal
  103.  * Purpose: Set palette to be written out with subsequent images
  104.  * Inputs:  pal: palette to associate with subsequent images
  105.  * Returns: 0 on success, -1 on failure with DFerror set
  106.  * Users:   Fortran stub routine
  107.  * Invokes: DFR8setpalette
  108.  *---------------------------------------------------------------------------*/
  109.  
  110.     FRETVAL(intf)
  111. #ifdef PROTOTYPE
  112. nd8spal(_fcd pal)
  113. #else
  114. nd8spal(pal)
  115.     _fcd pal;
  116. #endif /* PROTOTYPE */
  117. {
  118.     return (DFR8setpalette((uint8 *)_fcdtocp(pal)));
  119. }
  120.  
  121.  
  122. /*-----------------------------------------------------------------------------
  123.  * Name:    d8first
  124.  * Purpose: Reset sequencing back to first image
  125.  * Inputs:  none
  126.  * Returns: 0 on success, -1 on failure with DFerror set
  127.  * Users:   Fortran stub routine
  128.  * Invokes: DFR8restart
  129.  *---------------------------------------------------------------------------*/
  130.  
  131.     FRETVAL(intf)
  132. #ifdef PROTOTYPE
  133. nd8first(void)
  134. #else
  135. nd8first()
  136. #endif /* PROTOTYPE */
  137. {
  138.     return(DFR8restart());
  139. }
  140.  
  141. /*-----------------------------------------------------------------------------
  142.  * Name:    d8igdim
  143.  * Purpose: Get dimensions of next image using DFR8getdims
  144.  * Inputs:  filename: name of HDF file
  145.  *          xdim, ydim - integers to return dimensions in
  146.  *          ispal - boolean to indicate whether the image includes a palette
  147.  *          lenfn - length of filename
  148.  * Returns: 0 on success, -1 on failure with DFerror set
  149.  * Users:   Fortran stub routine
  150.  * Invokes: DFR8getdims
  151.  *---------------------------------------------------------------------------*/
  152.  
  153.     FRETVAL(intf)
  154. #ifdef PROTOTYPE
  155. nd8igdim(_fcd filename, intf *xdim, intf *ydim, intf *ispal, intf *lenfn)
  156. #else
  157. nd8igdim(filename, xdim, ydim, ispal, lenfn)
  158.     _fcd filename;
  159.     intf *xdim, *ydim;
  160.     intf *ispal, *lenfn;
  161. #endif /* PROTOTYPE */
  162. {
  163.     char *fn;
  164.     intf ret;
  165.  
  166.     fn = HDf2cstring(filename, *lenfn);
  167.     ret =  DFR8getdims(fn, (int32 *)xdim, (int32 *)ydim, (intn *)ispal);
  168.     HDfreespace(fn);
  169.     return(ret);
  170. }
  171.  
  172.  
  173. /*-----------------------------------------------------------------------------
  174.  * Name:    d8igimg
  175.  * Purpose: Get next image using DFR8getimage
  176.  * Inputs:  filename: name of HDF file
  177.  *          image: space provided for returning image
  178.  *          xdim, ydim: dimension of space provided for image
  179.  *          pal: space of 768 bytes for palette
  180.  *          lenfn: length of filename
  181.  * Returns: 0 on success, -1 on failure with DFerror set
  182.  * Users:   Fortran stub routine
  183.  * Invokes: DFR8getimage
  184.  *---------------------------------------------------------------------------*/
  185.  
  186.     FRETVAL(intf)
  187. #ifdef PROTOTYPE
  188. nd8igimg(_fcd filename, _fcd image, intf *xdim, intf *ydim, _fcd pal, intf *lenfn)
  189. #else
  190. nd8igimg(filename, image, xdim, ydim, pal, lenfn)
  191.     _fcd filename, image, pal;
  192.     intf *xdim, *ydim;
  193.     intf *lenfn;
  194. #endif /* PROTOTYPE */
  195. {
  196.     char *fn;
  197.     intf ret;
  198.  
  199.     fn = HDf2cstring(filename, *lenfn);
  200.     ret =  DFR8getimage(fn, (uint8 *)_fcdtocp(image), *xdim, *ydim,
  201.             (uint8 *)_fcdtocp(pal));
  202.     HDfreespace(fn);
  203.     return(ret);
  204. }
  205.  
  206.  
  207. /*-----------------------------------------------------------------------------
  208.  * Name:    d8ipimg
  209.  * Purpose: Write out image to new file
  210.  * Inputs:  filename: name of HDF file
  211.  *          image: image to write out
  212.  *          xdim, ydim: dimensions of image to write out
  213.  *          compress: compression scheme
  214.  *          lenfn: length of filename
  215.  * Returns: 0 on success, -1 on failure with DFerror set
  216.  * Users:   Fortran stub routine
  217.  * Invokes: DFR8putimage
  218.  *---------------------------------------------------------------------------*/
  219.  
  220.     FRETVAL(intf)
  221. #ifdef PROTOTYPE
  222. nd8ipimg(_fcd filename, _fcd image, intf *xdim, intf *ydim, intf *compress,
  223.      intf *lenfn)
  224. #else
  225. nd8ipimg(filename, image, xdim, ydim, compress, lenfn)
  226.     _fcd filename, image;
  227.     intf *xdim, *ydim;
  228.     intf *compress, *lenfn;
  229. #endif /* PROTOTYPE */
  230. {
  231.     char *fn;
  232.     intf ret;
  233.  
  234.     fn = HDf2cstring(filename, *lenfn);
  235.     ret = DFR8putimage(fn, (VOIDP)_fcdtocp(image), *xdim, *ydim, *compress);
  236.     HDfreespace(fn);
  237.     return(ret);
  238. }
  239.  
  240.  
  241. /*-----------------------------------------------------------------------------
  242.  * Name:    d8iaimg
  243.  * Purpose: Add image to existing file
  244.  * Inputs:  filename: name of HDF file
  245.  *          image: image to write out
  246.  *          xdim, ydim: dimensions of image to write out
  247.  *          compress: compression scheme
  248.  *          lenfn: length of filename
  249.  * Returns: 0 on success, -1 on failure with DFerror set
  250.  * Users:   Fortran stub routine
  251.  * Invokes: DFR8addimage
  252.  *---------------------------------------------------------------------------*/
  253.  
  254.     FRETVAL(intf)
  255. #ifdef PROTOTYPE
  256. nd8iaimg(_fcd filename, _fcd image, intf *xdim, intf *ydim, intf *compress,
  257.      intf *lenfn)
  258. #else
  259. nd8iaimg(filename, image, xdim, ydim, compress, lenfn)
  260.     _fcd filename, image;
  261.     intf *xdim, *ydim;
  262.     intf *compress, *lenfn;
  263. #endif /* PROTOTYPE */
  264. {
  265.     char *fn;
  266.     intf ret;
  267.  
  268.     fn = HDf2cstring(filename, *lenfn);
  269.     ret = DFR8addimage(fn, (VOIDP)_fcdtocp(image), *xdim, *ydim, *compress);
  270.     HDfreespace(fn);
  271.     return(ret);
  272. }
  273.  
  274. /*-----------------------------------------------------------------------------
  275.  * Name:    D8irref
  276.  * Purpose: Set ref of image to get next
  277.  * Inputs:  filename: file to which this applies
  278.  *          ref: reference number of next get
  279.  * Returns: 0 on success, -1 on failure
  280.  * Users:   HDF programmers, other routines and utilities
  281.  * Invokes: DFR8Iopen, DFIfind
  282.  * Remarks: checks if image with this ref exists
  283.  *---------------------------------------------------------------------------*/
  284.  
  285.     FRETVAL(intf)
  286. #ifdef PROTOTYPE
  287. nd8irref(_fcd filename, intf *ref, intf *fnlen)
  288. #else
  289. nd8irref(filename, ref, fnlen)
  290.     _fcd filename;
  291.     intf *ref;
  292.     intf  *fnlen;
  293. #endif /* PROTOTYPE */
  294. {
  295.     char *fn;
  296.     intf ret;
  297.     uint16 Ref;
  298.     
  299.     Ref = (uint16) *ref;
  300.  
  301.     fn = HDf2cstring(filename, *fnlen);
  302.     if (!fn) return -1;
  303.     ret = DFR8readref(fn, Ref);
  304.     HDfreespace(fn);
  305.     return ret;
  306. }
  307.  
  308.  
  309. /*-----------------------------------------------------------------------------
  310.  * Name:    d8iwref
  311.  * Purpose: Set ref of image to put next
  312.  * Inputs:  filename: file to which this applies
  313.  *          fnlen: length of the filename
  314.  * Returns: 0 on success, -1 on failure
  315.  * Users:   HDF programmers, other routines and utilities
  316.  * Invokes: DFR8writeref
  317.  * Remarks: 
  318.  *---------------------------------------------------------------------------*/
  319.  
  320.     FRETVAL(intf)
  321. #ifdef PROTOTYPE
  322. nd8iwref(_fcd filename, intf *ref, intf *fnlen)
  323. #else
  324. nd8iwref(filename, ref, fnlen)
  325.     _fcd filename;
  326.     intf *ref;
  327.     intf *fnlen;
  328. #endif /* PROTOTYPE */
  329. {
  330.     char *fn;
  331.     intf ret;
  332.     uint16 Ref;
  333.  
  334.     Ref = (uint16) *ref;
  335.  
  336.     fn = HDf2cstring(filename, *fnlen);
  337.     ret = DFR8writeref(fn, Ref);
  338.     HDfreespace(fn);
  339.     return (ret);
  340. }
  341.  
  342.  
  343. /*-----------------------------------------------------------------------------
  344.  * Name:    d8inims
  345.  * Purpose: How many images are present in this file?
  346.  * Inputs:  filename: file to which this applies
  347.  *          fnlen: length of HDF file name
  348.  * Returns: number of images on success, -1 on failure
  349.  * Users:   HDF programmers, other routines and utilities
  350.  * Invokes: DFR8nimages
  351.  * Remarks: 
  352.  *---------------------------------------------------------------------------*/
  353.  
  354.     FRETVAL(intf)
  355. #ifdef PROTOTYPE
  356. nd8inims(_fcd filename, intf *fnlen)
  357. #else
  358. nd8inims(filename, fnlen)
  359.     _fcd filename;
  360.     intf *fnlen;
  361. #endif /* PROTOTYPE */
  362. {
  363.     char *fn;
  364.     intf ret;
  365.  
  366.     fn = HDf2cstring(filename, *fnlen);
  367.     ret = DFR8nimages(fn);
  368.     HDfreespace(fn);
  369.     return (ret);
  370. }
  371.  
  372.  
  373. /*-----------------------------------------------------------------------------
  374.  * Name:    d8lref
  375.  * Purpose: return reference number of last element read or written
  376.  * Inputs:  none
  377.  * Returns: 0 on success, -1 on failure with error set
  378.  * Users:   Fortran stub routine
  379.  * Invokes: DFR8lastref
  380.  *---------------------------------------------------------------------------*/
  381.  
  382.         FRETVAL(intf)
  383. #ifdef PROTOTYPE
  384. nd8lref(void)
  385. #else
  386. nd8lref()
  387. #endif  /* PROTOTYPE */
  388. {
  389.     return(DFR8lastref());
  390. }
  391.  
  392. /*-----------------------------------------------------------------------------
  393.  * Name:    dfr8lastref
  394.  * Purpose: Return last ref written or read
  395.  * Inputs:  none
  396.  * Returns: ref on success, -1 on failure
  397.  * Users:   HDF programmers, other routines and utilities
  398.  * Invokes: DFR8lastref
  399.  * Remarks: 
  400.  *---------------------------------------------------------------------------*/
  401.  
  402.     FRETVAL(intf)
  403. #ifdef PROTOTYPE
  404. ndfr8lastref(void)
  405. #else
  406. ndfr8lastref()
  407. #endif /* PROTOTYPE */
  408. {
  409.     return(DFR8lastref());
  410. }
  411.  
  412.  
  413. /*-----------------------------------------------------------------------------
  414.  * Name:    dfr8setpalette
  415.  * Purpose: Set palette to be written out with subsequent images
  416.  * Inputs:  pal: palette to associate with subsequent images
  417.  * Returns: 0 on success, -1 on failure with DFerror set
  418.  * Users:   Fortran stub routine
  419.  * Invokes: DFR8setpalette
  420.  *---------------------------------------------------------------------------*/
  421.  
  422.     FRETVAL(intf)
  423. #ifdef PROTOTYPE
  424. ndfr8setpalette(_fcd pal)
  425. #else
  426. ndfr8setpalette(pal)
  427.     _fcd pal;
  428. #endif /* PROTOTYPE */
  429. {
  430.  
  431.     return (DFR8setpalette((uint8 *)_fcdtocp(pal)));
  432. }
  433.  
  434. /*-----------------------------------------------------------------------------
  435.  * Name:    dfr8restart
  436.  * Purpose: Reset sequencing back to first image
  437.  * Inputs:  none
  438.  * Returns: 0 on success, -1 on failure with DFerror set
  439.  * Users:   Fortran stub routine
  440.  * Invokes: DFR8restart
  441.  *---------------------------------------------------------------------------*/
  442.  
  443.     FRETVAL(intf)
  444. #ifdef PROTOTYPE
  445. ndfr8restart(void)
  446. #else
  447. ndfr8restart()
  448. #endif /* PROTOTYPE */
  449. {
  450.  
  451.     return(DFR8restart());
  452. }
  453.  
  454.